package gate

import (
	"gitee.com/goxiang2/server/lib/lib_rpc"
	"log"
	"net"
)

type GxGate struct {
}

func init() {
	// 服务注册
	lib_rpc.RegisterService("Gate", &GxGate{})
}

// Run 服务启动函数
func (gate *GxGate) Run() error {
	port := ":10001"
	listener, err := net.Listen("tcp", port)
	if err != nil {
		log.Printf("lister %s fail\n", port)
		return err
	}
	log.Println("gate start, host:", port)

	for {
		conn, err1 := listener.Accept()
		if err1 != nil {
			log.Printf("server Accept fail, err:", err1.Error())
			return err1
		}
		log.Println("new connect", conn.RemoteAddr().String())
		go connRun(conn)
	}
}
